/**
 * 
 */
package com.bot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bot.mapper.MajorMapper;
import com.bot.pojo.Area;
import com.bot.pojo.Major;
import com.bot.pojo.Student;
import com.bot.service.MajorService;
import com.github.pagehelper.PageInfo;

/**
 * @author zhaoyan
 *
 * 2020年2月4日
 */
@Controller
public class MajorController {
	
	
	
	@Autowired
	private MajorService majorService;
	
	
	@RequestMapping("/")
	public String findStuByCon(@RequestParam(defaultValue = "1")Integer pageNum,Student student,Model m) {
		
	
		
		PageInfo<Student> studnetPage = majorService.findStu(pageNum,student);
		
		
		System.out.println(student.getIds());
		
		m.addAttribute("studnetPage",studnetPage );
		
		
		
		return "index";
		
	}
	
	@RequestMapping("toAddStudent")
	public String toAddStudent(Model m) {
		
		List<Major> listMaj = majorService.findMajor();
		
		m.addAttribute("listMaj",listMaj);
		
		return "add";
	}
	
	@RequestMapping("add")
	@ResponseBody
	public Integer addStu(Student student) {
				
		return majorService.addStu(student);
		
	}
	
	@RequestMapping("toUpdate")
	public String toUpdate(Model m) {
		List<Major> listMaj = majorService.findMajor();
		
		m.addAttribute("listMaj",listMaj);
		
		return "update";	
		
	}
	
	@RequestMapping("findStu")
	@ResponseBody
	public Student findStu(Integer id) {
		
		
		return majorService.findStuById(id);
		
	}

	@RequestMapping("findMaj")
	@ResponseBody
	public List<Integer> findMaj(Integer id){
		
		
		return majorService.findMaj(id);
	}
	
	@RequestMapping("update")
	@ResponseBody
	public Integer updateStu(Student student) {
				
		return majorService.updateStu(student);
		
	}
	
	@RequestMapping("delById")
	@ResponseBody
	public Integer delStu(@RequestParam(value = "list" ,required = false) List<Integer> list) {
		
		System.err.println("ids是--"+ list);
		
		return  majorService.delStu(list);
		
		
	}
	
	
	@RequestMapping("findAreaById")
	@ResponseBody
	public List<Area> findAreaById(@RequestParam(defaultValue = "0")Integer pid){
		
		
		return majorService.findAreaById(pid);
	}
	
//	@RequestMapping("toDemo")
//	public String toDemo() {
//		
//		
//		return "demo";
//	}
//	
//	@RequestMapping("del")
//	public String  del(@RequestParam(value = "idss",required = false)List<Integer> idss) {
//		
//		System.out.println(idss);
//
//		
//		return "redirect:/";
//	}
//	
}
